package org.test.rpc;

import java.io.IOException;

import org.apache.hadoop.ipc.ProtocolSignature;
import org.test.rpc.proto.EchoUserProtocol.RequestProto;
import org.test.rpc.proto.EchoUserProtocol.ResponseProto;

import com.google.protobuf.RpcController;
import com.google.protobuf.ServiceException;

public class EchoPBService implements EchoPB {

	public ResponseProto echo(RpcController controller, RequestProto request)
			throws ServiceException {
		return ResponseProto.newBuilder().setResult("receive: "+request.getReq()).build();
	}

	public long getProtocolVersion(String protocol, long clientVersion)
			throws IOException {
		return versionID;
	}

	public ProtocolSignature getProtocolSignature(String protocol,
			long clientVersion, int clientMethodsHash) throws IOException {
		if (protocol.equals(EchoPB.class.getName())){
	        return new ProtocolSignature(versionID, null);
		}
	    throw new IOException("Unknown protocol: " + protocol);
	}

}
